import axios from "axios";
import { nanoid } from "nanoid";

export default {
    // 开启命名空间配置
    namespaced: true,
    state: {
        personList: [
            {
                id: "W8hqg9yBT_6O-0jfolWC3",
                name: "你逆光而来配得上这世间所有的好。",
            },
            { id: "D1vME3usxM2aS1-CzLSQ3", name: "容我爱你，深不见底" },
        ],
    },
    getters: {
        nol(state) {
            return state.personList.length;
        },
    },
    mutations: {
        ADD_PERSON(state, value) {
            let person = { id: nanoid(), name: value };
            state.personList.unshift(person);
        },
    },
    actions: {
        addPerson(context, value) {
            axios.get("https://api.uixsj.cn/hitokoto/get?type=social").then(
                (response) => {
                    context.commit("ADD_PERSON", response.data);
                },
                (error) => {
                    alert(error.message);
                }
            );
        },
    },
};
